﻿using Microsoft.ManagementConsole.Controls;
using Microsoft.ManagementConsole.SnapIns.Integration;
using PlanckTime.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Microsoft.ManagementConsole.SnapIns.Controls
{
    public class PlanckTimePropertyPage : PropertyPage
    {
        PlanckTimeNode currentNode;


        public PlanckTimePropertyPage(PlanckTimeNode currentNode)
        {
            this.currentNode = currentNode;
            this.Title = "Task Operation";
            this.Control = taskOperationControl = new PlanckTimeNewTaskControl();
        }

        protected override void OnInitialize()
        {
            base.OnInitialize();
            this.Dirty = true;
        }

        protected override bool OnApply()
        {
            var taskName = this.taskOperationControl.txtTaskName.Text;

            PlanckTimeServices.Instance.Save(new Task()
                {
                    Name = taskName,
                    ParentId = (this.currentNode.Tag as Task).Id,
                    Status = "New"
                });

            currentNode.Refresh();

            this.taskOperationControl.lblStatus.Text = "New task saved";

            return base.OnApply();
        }

        public PlanckTimeNewTaskControl taskOperationControl { get; set; }
    }
}
